import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
import state from './state'
import mutations from './mutations'
import actions from './actions'
export default new Vuex.Store({
  state,
  mutations,
  getters:{
	  goodsnum({shopcart,isDenglu}){
		  if(!isDenglu.token){
			 return 0
		  }else{
			  return Object.values(shopcart).filter(item=>item.isChecked).map(item=>item.num).reduce((prev,now)=>prev+now,0)
		  }
		  
	  },
	  goodsprice({shopcart}){
	  		  return Object.values(shopcart).filter(item=>item.isChecked).map(item=>item.price*item.num).reduce((prev,now)=>prev+now,0)
	  },
	  goodsisChecked({shopcart}){
		  return Object.values(shopcart).every(item=>item.isChecked)
	  },
	  // 是否有商品
	  isHisGoods({shopcart}){
	  		  return Object.values(shopcart).length != 0
	  },
  }
  // actions,
  // modules
})
